package web.Courts;

import services.CourtsServiceAll;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Timestamp;
import java.time.Instant;
import java.time.LocalDateTime;
import java.time.ZoneId;

@WebServlet("/UpdateStatus")
public class UpdateStatus extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        resp.setContentType("application/json");
        Timestamp now = Timestamp.valueOf(LocalDateTime.now(ZoneId.systemDefault()));
        String courts_table = req.getParameter("courts_table");
        int num = 0;
        if("0".equals(req.getParameter("courts_status_id"))){
            num = new CourtsServiceAll().updateStatusBooking(courts_table,1,now);
        }else{
            Instant currentInstant = now.toInstant();
            num = new CourtsServiceAll().updateStatusSettle(courts_table,0,now);
        }
        resp.getWriter().println(num > 0?"修改成功":"修改失败");
    }
}
